package com.wyq.dao.impl;

import java.util.List;
import java.util.Map;

import com.wyq.bean.MailInfo;
import com.wyq.dao.MailInfoDAO;
import com.wyq.util.impl.JDBCDAOSupportImpl;

public class MailInfoDAOImpl extends JDBCDAOSupportImpl implements MailInfoDAO {

	//服务邮箱只能存在一条数据 id 为101
	public List getMailInfo() throws Exception {
		String sql = "select * from mail_info where id = 101 ";
		List list = this.getListMapBySql(sql);
		return list;
	}

	public int saveMailInfo(MailInfo mailInfo) {
		return 0;
	}

	public int updateMailInfo(Map mailInfo) throws Exception {
		List list = this.getMailInfo();
		String sql = "";
		if(list.size() <= 0){
			sql = "insert into mail_info(id,mailServerHost,mailServerAddress,mailServerPassword,isAvailable) values("
				+"101"
				+ ",'" + mailInfo.get("mailServerHost") + "'"
				+ ",'" + mailInfo.get("mailServerAddress") + "'"
				+ ",'" + mailInfo.get("mailServerPassword") + "'"
				+ ",1)"; 
		}else{
			sql = "update mail_info set mailServerHost = '" + mailInfo.get("mailServerHost")
				+ "',mailServerAddress = '" + mailInfo.get("mailServerAddress")
				+ "',mailServerPassword = '" + mailInfo.get("mailServerPassword")
				+ "',isAvailable = 1"
				+ " where id = " + ((Map)list.get(0)).get("id");
		}
		int flag = this.execupdateBySql(sql);
		return flag;
	}

}
